<?php

namespace common\models\business;

use Yii;

/**
 * This is the model class for table "business_cost_type".
 *
 * @property string $id
 * @property string $name
 * @property integer $type
 * @property string $remark
 * @property integer $createtime
 */
class BusinessCostType extends \yii\db\ActiveRecord
{



    const TYPE_PIG = 1;
    const TYPE_HOUSE = 2;
    const TYPE_FARMER = 3;
    const TYPE_PERSON = 4;
    public static $types = [
        self::TYPE_PIG => '用于仔猪',
        self::TYPE_HOUSE => '用于农家乐',
        self::TYPE_FARMER => '用于农户',
        self::TYPE_PERSON => '用于巡检员',
    ];


    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '成本类型',      //用于修改了什么的显示
        'mainfield' => 'name',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'business_cost_type';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['type', 'createtime'], 'integer'],
            [['name'], 'string', 'max' => 20],
            [['remark'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '名称',
            'type' => '类型',
            'remark' => '备注说明',
            'createtime' => '创建时间',
        ];
    }

    public function beforeSave($insert)
    {
        if($this->isNewRecord){
            $this->createtime = time();
        }
        return parent::beforeSave($insert); // TODO: Change the autogenerated stub
    }
}
